package
{	
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.utils.Dictionary;
	
	public class ResourceMgr
	{
		[Embed(source="default_role.png")]
		public static var DefaultRoleImage:Class;
		
		[Embed(source="cursor1.png")]
		public static var Cursor1:Class;	

		[Embed(source="cursor2.png")]
		public static var Cursor2:Class;			
		
		private var res:Dictionary = new Dictionary();
		
		private static var rmInst:ResourceMgr;
		
		public static function GetInstance():ResourceMgr
		{
			if(rmInst == null)
			{
				rmInst = new ResourceMgr();
			}
			
			return rmInst;
		}		
		
		public function loadImage(str:String):void
		{
			var imageLoader:Loader = new Loader();
			imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,
				imageLoadComplete);
			imageLoader.load(new URLRequest(str));	
			imageLoader.name = str;		
		}
		
		private function imageLoadComplete(event:Event):void
		{	
			var str:String = (event.target as LoaderInfo).loader.name;
			//trace("load complete:"+str);
			
			var bp:BitmapData = event.target.content.bitmapData;
			if(bp != null)
			{
				res[str] = bp;
			}			
		}	
		
		public function getImage(str:String):BitmapData
		{
			return res[str];
		}
		
	}
}